import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from  '@/views/Login.vue'
import Home from '@/views/Home.vue'
import UserList from '@/views/user/UserList.vue'
import RoleList from '@/views/role/RoleList.vue'
import Menus from '@/views/menu/Menus.vue'
import linkman from "../views/linkman/linkman";
import AddLinkMan from "../views/linkman/AddLinkMan";
import CustomerList from "../views/customer/CustomerList";
import CustomerAdd from "../views/customer/CustomerAdd";
import CustomerMx from "../views/customer/CustomerMx";
import MaterialMenu from "../views/material/MaterialMenu";
import addMaterial from "../views/material/addMaterial";
import LookMaterial from "../views/material/LookMaterial";
import UpdateMaterial from "../views/material/UpdateMaterial";
import LinkManDetail from "../views/linkman/LinkManDetail";
import CustLinKen from "../views/customer/CustLinKen";
import ProcessList from "../views/process/ProcessList";
import AddProcess from "../views/process/AddProcess";
import LookProcess from "../views/process/LookProcess";
import UpdateProess from "../views/process/UpdateProess";
import technologyList from "../views/technology/technologyList";
import CustomerLogin from "../views/customer/CustomerLogin";
import CustomerHome from "../views/customer/CustomerHome";

Vue.use(VueRouter)

const routes = [
  {path: '/customerHome',component: CustomerHome},
  {path:'/',redirect:'/login'},
  {name:'登录',path:'/login',component:Login},
  {name:'客户登录页面',path: '/customerLogin',component:CustomerLogin},
  {name:'主页',path:'/home',component:Home,children:[
      {name:'用户管理',path:'/userList',component:UserList},
      {name:'角色管理',path:'/roleList',component:RoleList},
      {name:'菜单管理',path:'/menus',component:Menus},
      {name:'联系人管理',path:'/linkmanList',component: linkman},
      {name: '添加联系人',path: '/AddLinkMan',component: AddLinkMan},
      {name: '联系人详情',path: '/lookDetail',component: LinkManDetail},
      {name:'客户管理',path:'/customer',component:CustomerList},
      {name:'添加客户',path:'/add',component:CustomerAdd},
      {name:'客户详情',path:'/details',component:CustomerMx},
      {name:'原材料管理',path:'/materialMenu',component:MaterialMenu},
      {name:'原材料添加',path:'/addMaterial',component:addMaterial},
      {name:'原材料详情',path:'/lookMaterial',component:LookMaterial},
      {name:'原材料编辑',path:'/updateMaterial',component:UpdateMaterial},
      {name: '客户联系人',path: '/toLinken',component: CustLinKen},
      {name:'工序管理',path:'/processList',component:ProcessList},
      {name:'工序添加',path:'/addProcess',component:AddProcess},
      {name:'工序详情',path:'/lookProcess',component:LookProcess},
      {name:'工序修改',path:'/updateProcess',component:UpdateProess},
      {name:'工艺列表',path: '/technologyList',component: technologyList},
    ]
  },

]

const router = new VueRouter({
  routes
})

router.beforeEach(function (to, from, next) {//to 路由目标 //from  //next 拦截补拦截，拦截到哪 路由守卫

  if(to.path=='/login'){ //当访问登录组件不拦截
    return next();
  }
  if (to.path=='/customerLogin'){
    return next();
  }
  let user=sessionStorage.getItem("user");//获取sessionStorage中用户的信息
  if(user){
    //当前用户已登录
    return next();//继续访问
  }

  return  next('/login');
})


export default router
